package com.kldy8.kldyw;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;
import com.kldy8.kldyw.logre.UserInfo;
import com.kldy8.kldyw.sharedpreference.SharedPreUtil;
import com.kldy8.kldyw.system.AccountType;
import com.kldy8.kldyw.system.DataCleanManager;

import java.util.List;

import cn.sharesdk.framework.ShareSDK;

/**
 * Created by Administrator on 2016/8/19.
 */
public class SystemSet extends Application
{
    //第三方
    public  UserInfo getUserInfo() {
        return userInfo;
    }public void     setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }private UserInfo userInfo = new UserInfo();
    private String assestoken  = "";


    private AccountType  accountType ;

    private String token = "";
    private String member_id = "";

    //0为个人  1为企业
    private String f_person = "0";
    private String auth_personal="0";////身份认证
    private String auth_enterprise="0";////企业认证
    private String auth_actor="0";////演员资料完善
    private String auth_writer="0";////作家资料完善


    private String lon  = "";
    private String lat = "";

    public AccountType getAccountType()
    {
        return accountType;
    }

    public void setAccountType(AccountType accountType)
    {
        this.accountType = accountType;
    }

    public String getAssestoken() {
        return assestoken;
    }

    public void setAssestoken(String assestoken) {
        this.assestoken = assestoken;
    }

    public String getLat() {
        return lat;
    }

    public void setLat(String lat) {
        this.lat = lat;
    }

    public String getLon() {
        return lon;
    }

    public void setLon(String lon) {
        this.lon = lon;
    }

    public String getToken()
    {
        return token;
    }

    public void setToken(String token)
    {
        this.token = token;
    }



    public String getAuth_personal() {
        return auth_personal;
    }

    public void setAuth_personal(String auth_personal) {
        this.auth_personal = auth_personal;
    }

    public String getAuth_enterprise() {
        return auth_enterprise;
    }

    public void setAuth_enterprise(String auth_enterprise) {
        this.auth_enterprise = auth_enterprise;
    }

    public String getAuth_actor() {
        return auth_actor;
    }

    public void setAuth_actor(String auth_actor) {
        this.auth_actor = auth_actor;
    }

    public String getAuth_writer() {
        return auth_writer;
    }

    public void setAuth_writer(String auth_writer) {
        this.auth_writer = auth_writer;
    }

    public String getMember_id() {
        return member_id;
    }

    public void setMember_id(String member_id) {
        this.member_id = member_id;
    }

    public String getF_person()
    {
        return f_person;
    }

    public void setF_person(String f_person)
    {
        this.f_person = f_person;
    }

    public void clean(Context context)
    {
        token = "";
        member_id = "";
        f_person = "";

        DataCleanManager.cleanInternalCache(context);

        SharedPreUtil.getInstance();
        if (SharedPreUtil.getInstance() ==  null)
        {
            SharedPreUtil.initSharedPreference(context);
        }
       SharedPreUtil.getInstance().DeleteUser();
    }


    public void removeAllCookie(WebView wb)
    {
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(wb.getContext());
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeSessionCookie();

        //String testcookie1 = cookieManager.getCookie(urlpath);

        cookieManager.removeAllCookie();
        cookieSyncManager.sync();

        //String testcookie2 = cookieManager.getCookie(urlpath);
    }

    public void removeContextAllCookie(Context mContext)
    {
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mContext);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeSessionCookie();

        //String testcookie1 = cookieManager.getCookie(urlpath);

        cookieManager.removeAllCookie();
        cookieSyncManager.sync();

        //String testcookie2 = cookieManager.getCookie(urlpath);
    }


    @Override
    public void onCreate()
    {
        super.onCreate();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
        mContext = this;
        instance = this;
        initLocationClient();
        ShareSDK.initSDK(this);
        accountType = new AccountType(this);
    }

    private void initLocationClient()
    {
        //初始化定位
        mLocationClient = new AMapLocationClient(getApplicationContext());
        //设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);
    }


    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
    public AMapLocationListener mLocationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation amapLocation) {
            if (amapLocation != null) {
                if (amapLocation.getErrorCode() == 0)
                {
                    if (amapLocation != null)
                    {
                        setLat("" + amapLocation.getLatitude());
                        setLon("" + amapLocation.getLongitude());
                    }
                }
                else
                {
                    //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
                    Log.e("AmapError", "location Error, ErrCode:"
                            + amapLocation.getErrorCode() + ", errInfo:"
                            + amapLocation.getErrorInfo());
                }
            }
        }
    };

    private static SystemSet instance;

    public static SystemSet getInstance() {
        return instance;
    }

    private static Context mContext;

    public static Context getAppContext() {
        return mContext;
    }
}

